package com.platform.admin.config;

import java.util.concurrent.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ExecutorServiceConfig {

  @Bean
  public ExecutorService executorService() {
    int coreSize = Runtime.getRuntime().availableProcessors();
    // 核心线程数：2倍的cpu核数加1；    最大线程数：5倍的cpu核数
    return new ThreadPoolExecutor(
        2 * coreSize + 1,
        5 * coreSize,
        5L,
        TimeUnit.MINUTES,
        new SynchronousQueue<>(),
        new ThreadPoolExecutor.CallerRunsPolicy());
  }
}
